home *** CD-ROM | disk | FTP | other *** search
/ Web Page Construction Kit 3.0 / Web Page Construction Kit 3.0.iso / pc / source / 3rdparty / java / jdesnpro / data.1 / JDPLayout3.java < prev    next >
Encoding:
Text File  |  1996-08-02  |  16.9 KB  |  608 lines

  1. >XXX0609  Total lines for the build status message calculation
  2. //--------------------------------------------------------------------
  3. //                                                                    
  4. >001//  Module:       <JDPModule>                                       
  5. >002//  Description:  <Class Description>
  6. //                                                                    
  7. //--------------------------------------------------------------------
  8.  
  9. import java.awt.*;
  10. import java.applet.*;
  11. import java.util.StringTokenizer;
  12. import java.util.Vector;
  13.  
  14.  
  15. >003public class <JDPUserBill> extends JDPClassLayout {
  16.  
  17.     JDPUser user;
  18.     JDPJagg jaggSQL;
  19.     JDPWhereClause jdpWhereClause;
  20.     JDPSearchResults searchResults;
  21.     JDPTextGrid tableContents;
  22.  
  23.     String[] psortChoice;
  24.     String[] pdisplayChoice;
  25.     int itemIndex;
  26.     boolean insertRequested = false;
  27.     boolean deleteRequested = false;
  28.     String pfromWhereClause;
  29.     String[][] rowKey;
  30.     int keyCount;
  31.     int prevColumnCount;
  32. >119    int columnCount = <columnCount>;
  33.  
  34.     //
  35.     //  Declare screen components
  36.     //
  37. >004    <TextField username>;
  38.  
  39.  
  40.     public void InitClass(JDPUser user, Panel targetPanel, String moduleParameter) {
  41.  
  42.         this.user = user;
  43.         //
  44.         //  Set JAGG settings for this class
  45.         //
  46.         jaggSQL = new JDPJagg(user.jaggPath);
  47.         jaggSQL.setNULL("space");
  48. >997        jaggSQL.setMRW("<maxRows>");
  49. >998        jaggSQL.setDSN("<datasource>");
  50. >999        jaggSQL.setCSTR("<connectstr>");
  51.  
  52.         setLayout(new BorderLayout());
  53.         setFont(user.plainFont);
  54.  
  55.         Panel mainPanel = new Panel();
  56.         mainPanel.setLayout(new BorderLayout());
  57.         Panel centerPanel = new Panel();
  58.         centerPanel.setLayout(new BorderLayout());
  59.         Panel centerMainPanel = new Panel();
  60.         centerMainPanel.setLayout(new GridLayout(2,1,1,1));
  61.         Panel centerTopPanel = new JDPScrollPanel();
  62.         Panel centerBottomPanel = new Panel();
  63.         centerBottomPanel.setLayout(new BorderLayout());
  64.         Panel leftPanel = new Panel();
  65.         leftPanel.setLayout(new BorderLayout());
  66.         
  67.         //
  68.         //  Define parameters for JDPSearchResults
  69.         //
  70. >005        String pselectFields = "<>"; String[] psdisplayFields = {<>};
  71. >006        pfromWhereClause = "<FROM JDPUser WHERE >";
  72.  
  73. >007        psortChoice = new String[<5>];
  74. >008        psortChoice[<0>] = "<username>";
  75.  
  76. >009        String[] psortChoiceText = {<"Sort by User Name","Sort by Card Number">};
  77.         pdisplayChoice = psortChoice;
  78.  
  79. >010        boolean pdisplayCount = <true>;
  80. >011        String pcountText = "<Total Entries:>";
  81.     
  82.         //
  83.         //  Create an instance of screen components
  84.         //
  85. >012        <username> = new <TextField("",20)>;
  86.  
  87.         //
  88.         //  Initialise any choice components
  89.         //
  90.         loadChoices();
  91.  
  92.         //
  93.         //  Add components to the screen
  94.         //
  95. >013        centerTopPanel.add("Left",new JDPWrapLabel(user,"<User Name:>",Color.<labelColor>));
  96. >014        centerTopPanel.add("Right",centerR<0>);
  97.  
  98.         centerMainPanel.add(centerTopPanel);
  99.         
  100.         // 
  101.         //  Set screen component attributes
  102.         //
  103. >039        <username>.setForeground(Color.<fcolor>);
  104. >040        <username>.setBackground(Color.<bcolor>);
  105.         
  106.         //
  107.         //  Create a new instance of a Grid
  108.         //
  109.         tableContents = new JDPTextGrid(user);
  110.         centerBottomPanel.add("Center",tableContents);
  111.         centerMainPanel.add(centerBottomPanel);
  112.         //
  113.         //  Add buttons to the bottom of the panel
  114.         //
  115.         if (moduleParameter.compareTo("Inquiry") == 0) {
  116. >041            <username>.setEditable(false);
  117.             String buttons[] = {""};
  118.             centerBottomPanel.add("South",new JDPButtons(user, buttons, JDPButtons.HORIZONTAL));
  119.         } else {
  120. >042            <username>.setEditable(<editable>);
  121. >015            String buttons[] = {<"   Apply   ","Reset","New","Copy","Remove">};
  122.             centerBottomPanel.add("South",new JDPButtons(user, buttons, JDPButtons.HORIZONTAL));
  123.         }
  124.         mainPanel.add("Center",centerMainPanel);
  125.         
  126.         //
  127.         //  Define parameters for JDPWhereClause
  128.         //
  129. >016        String[] pchooseFrom = new String[<7>];
  130. >017        pchooseFrom[<0>] = "<Account Name>";
  131.  
  132. >018        String[] pactualchooseFrom = new String[<7>];
  133. >019        pactualchooseFrom[<0>] = "<username>";
  134.  
  135. >020        String[][] pmatchUsing = new String[<7>][<7>];
  136. >021        pmatchUsing[<0>][<0>] = "<Begins with>";
  137.  
  138. >022        String[][] pactualmatchUsing = new String[<7>][<7>];
  139. >023        pactualmatchUsing[<0>][<0>] = "< like >";
  140.  
  141. >024        boolean[] constantIsString = new boolean[<7>];
  142. >025        constantIsString[<0>] = <true>;
  143.  
  144. >026        int[] constantLength = new int[<7>];
  145. >027        constantLength[<0>] = <20>;
  146.  
  147.         //
  148.         //  Add JDPWhereClause search panel
  149.         //
  150.         if (pchooseFrom.length > 0) {
  151. >028            jdpWhereClause = new JDPWhereClause(user, "<UserBill>", true, "<pinitChoice>", pchooseFrom, pactualchooseFrom,
  152.                                                 pmatchUsing, pactualmatchUsing, null, null,
  153.                                                 constantLength, constantIsString);
  154.             leftPanel.add("North",jdpWhereClause);
  155.         }
  156.         //
  157.         //  Add JDPSearchResults result list
  158.         //
  159.         if (psortChoice.length > 0) {
  160. >029            searchResults = new JDPSearchResults(user, <true>, jaggSQL, <false>, pselectFields, psdisplayFields, pfromWhereClause, psortChoiceText, psortChoice, pdisplayChoice, "<pinitChoice>", pdisplayCount, pcountText);
  161.             leftPanel.add("Center",searchResults);
  162.             mainPanel.add("West",leftPanel);
  163.         }
  164.  
  165. >030        add("Center",new JDPChiselFramePanel(user,"<User Billing Details>",mainPanel,"North"));
  166.         if (psortChoice.length > 0) {
  167.             newSearch();
  168.         }
  169.         // repaint the panel
  170.         targetPanel.add("Center",this);
  171.         targetPanel.paintAll(targetPanel.getGraphics());
  172.         //
  173.         //  Add the handle to this panel to the global vector so other panels can
  174.         //  access this one
  175.         //
  176.         user.gParm.addElement(this);
  177.     }
  178.  
  179.     //
  180.     //  Handle screen events
  181.     //
  182.     public boolean handleEvent(Event e) {
  183.  
  184.         switch (e.id) {
  185.         case Event.ACTION_EVENT:
  186.             if (e.target instanceof List) {
  187.                 if (e.target.equals(searchResults.resultList)) {
  188.                     loadData();
  189.                     return true;
  190.                 }
  191.             }
  192.             if (e.target instanceof JDPTreePicker) {
  193.                 if (e.target.equals(searchResults.tree)) {
  194.                     loadData();
  195.                     return true;
  196.                 }
  197.             }
  198.             if (e.target instanceof Button) {
  199.                 String choice = (String)e.arg;
  200.                 if (choice.trim().compareTo("Apply") == 0) {
  201.                     if (checkFields()) {
  202.                         checkRows();
  203.                     }
  204.                     return true;
  205.                 }
  206.                 if (choice.trim().compareTo("Reset") == 0) {
  207.                     if (insertRequested) {
  208.                         loadEmptyGrid();
  209.                     } else {
  210.                         loadGrid();
  211.                     }
  212.                     return true;
  213.                 }
  214.                 if (choice.trim().compareTo("Remove") == 0) {
  215.                     insertRequested = false;
  216.                     deleteRequested = true;
  217.                     checkRows();
  218.                     return true;
  219.                 }
  220.                 if (choice.trim().compareTo("Add") == 0) {
  221.                     if (!insertRequested) {
  222.                         insertRequested = true;
  223.                         loadEmptyGrid();
  224.                     }
  225.                     return true;
  226.                 }
  227.                 if (choice.trim().compareTo("Search") == 0) {
  228.                     insertRequested = false;
  229.                     newSearch();
  230.                     return true;
  231.                 }
  232.                 return true;
  233.             }
  234.             if (e.target instanceof Choice) {
  235.                 return true;
  236.             }
  237.             if (e.target instanceof TextField) {
  238.                 if ((jdpWhereClause != null) && (e.target.equals(jdpWhereClause.matchConstant))) {
  239.                     insertRequested = false;
  240.                     deleteRequested = false;
  241.                     newSearch();
  242.                     return true;
  243.                 }
  244.                 checkFields();
  245.                 return true;
  246.             }
  247.             return false;
  248.  
  249.         case Event.KEY_PRESS:
  250.             if (e.key == '\t') {
  251.                 //  handle tabbing between components
  252.                 if (e.modifiers != Event.SHIFT_MASK) {
  253. >031                    if (e.target.equals(<username>)) { user.u.cursor(<username>); return true; }
  254.                 } else {
  255. >038                    if (e.target.equals(<username>)) { user.u.cursor(<username>); return true; }
  256.                 }
  257.                 return true;
  258.             }
  259.             return false;
  260.  
  261.         case Event.WINDOW_EXPOSE:
  262.             if (e.target instanceof JDPTabSelectTopPanel) {
  263.                 //
  264.                 //  This is where you place code to get executed when this panel is
  265.                 //  reactivated from the tab menu
  266.                 //
  267.                 return true;
  268.             }
  269.             return false;
  270.  
  271.         default:
  272.             return false;
  273.  
  274.         }
  275.     }
  276.  
  277.     //
  278.     //  Retrieve the handle to another panel so as to be able to interact with it
  279.     //
  280.     public void retrieveHandle() {
  281.  
  282.         for (int ix=0; ix<user.gParm.size(); ix++) {
  283.             //
  284.             //  Activate the next four lines of code to retrieve the handle to another 
  285.             //  Panel within your JDP system. Of course you should declare the variable 
  286.             //  at the top of this source instead of within this method so you can 
  287.             //  access it from all the methods within this class. You only need to 
  288.             //  substitute DemoClass with the name ouf your class. You should call this 
  289.             //  method from somewhere else in this class. To access a variable from 
  290.             //  your resulting class use:
  291.             //     if (DemoClassHandle != null) mynewvar = demoClassHandle.variable;
  292.             //
  293. //            if (user.gParm.elementAt(ix) instanceof DemoClass19) {
  294. //                DemoClass19 DemoClassHandle = (DemoClass19)user.gParm.elementAt(ix);
  295. //                return;
  296. //            }
  297.         }
  298.     }
  299.  
  300.     //
  301.     //  The search button was pressed so rerun the query with the new search criteria
  302.     //
  303.     public void newSearch() {
  304.  
  305.         String whereClause;
  306.  
  307.         whereClause = pfromWhereClause;
  308.         if (jdpWhereClause != null) {
  309.             whereClause = whereClause + " AND " + jdpWhereClause.whereClause;
  310.         }
  311.         searchResults.setFromWhereClause(whereClause);
  312.         searchResults.clearList();
  313.         searchResults.loadList();
  314.     }
  315.  
  316.     //
  317.     //  Load the selected item
  318.     //
  319.     public void loadData() {
  320.  
  321.         StringTokenizer stok;
  322.  
  323.         int recCount = 0;
  324.         Vector results = new Vector();
  325.         String sep = jaggSQL.getSEP();
  326.         int actualRows = 0;
  327.         String row;
  328.         String tempText;
  329.  
  330.         if ((itemIndex = searchResults.getSelectedIndex()) < 0) {
  331.             clearFields();
  332.             return;
  333.         }
  334.  
  335. >032        String SQL = <SELECT>;
  336.  
  337.         user.mainmsg.setStatusMsg("Accessing database...", 0);
  338.         recCount = jaggSQL.execSQL(SQL, results);
  339.  
  340.         if(recCount == -1) {
  341.             System.out.println("loadData SQL: "+SQL);
  342.             user.mainmsg.setStatusMsg("SQL error. Contact the System Administrator", 20);
  343.             return;
  344.         }
  345.         if(recCount >= 1) {
  346.             row = (String)results.elementAt(0);
  347.             if ((row != null) && (row.trim().compareTo("") != 0)) {
  348.                 stok = new StringTokenizer(row);
  349.  
  350. >033                <username>.setText(stok.nextToken(sep).trim());
  351.             }
  352.             loadGrid();
  353. //            if(recCount > 1) {
  354. //                user.mainmsg.setStatusMsg("Multiple records found - first match only displayed.", 10);
  355. //            } else {
  356.                 user.mainmsg.clearStatusMsg();
  357. //            }
  358.         } else {
  359.             user.mainmsg.setStatusMsg("Requested entry does not exist.", 10);
  360.             clearFields();
  361.         }
  362.  
  363.     }
  364.  
  365.     //
  366.     //  Load the grid with the specified parameters and selected data
  367.     //
  368.     public void loadGrid() {
  369.  
  370.         StringTokenizer stok;
  371.         int recCount = 0;
  372.         Vector results = new Vector();
  373.         String sep = jaggSQL.getSEP();
  374.         int actualRows = 0;
  375.         String row;
  376.  
  377.         Vector columns = new Vector();
  378.         Vector indexes = new Vector();
  379.  
  380. >100        String SQL = <SELECT>;
  381.  
  382.         user.mainmsg.setStatusMsg("Accessing database...", 0);
  383.  
  384.         recCount = jaggSQL.execSQL(SQL, results);
  385.  
  386.         if(recCount == -1) {
  387.             user.mainmsg.setStatusMsg("SQL error. Contact the System Administrator", 20);
  388.             System.out.println("loadGrid SQL: " + SQL);
  389.             return;
  390.         }
  391.  
  392.         //
  393.         //  Initialise result arrays
  394.         //
  395.         actualRows = jaggSQL.getRowCount();
  396.         tableContents.currentText = new String[columnCount][actualRows];
  397.         //
  398.         //  If we haven't already initialise the grid settings
  399.         //
  400.         if (columnCount != prevColumnCount) {
  401.             prevColumnCount = columnCount;
  402.             setGridSettings();
  403.         }
  404.         tableContents.cellChanged = null;
  405.         tableContents.rowChanged = null;
  406.         tableContents.columnSelected = null;
  407. >120        keyCount = <keycount>;
  408.         rowKey = new String[actualRows][keyCount];
  409.         
  410.         //
  411.         //  Load key array and grid array
  412.         //
  413.         for (int ix=0; ix<actualRows; ix++) {
  414.             row = (String)results.elementAt(ix);
  415.             if ((row != null) && (row.trim().compareTo("") != 0)) {
  416.                 stok = new StringTokenizer(row);
  417.                 for (int iy=0; iy<keyCount; iy++) {
  418.                     rowKey[ix][iy] = stok.nextToken(sep).trim();
  419.                 }
  420.                 for (int iy=0; iy<columnCount; iy++) {
  421.                     tableContents.currentText[iy][ix] = stok.nextToken(sep).trim();
  422.                 }
  423.             }
  424.         }
  425.  
  426.         tableContents.newTable();
  427.  
  428.         //
  429.         //  Clear status message
  430.         //
  431.         user.mainmsg.clearStatusMsg();
  432.     }
  433.  
  434.     //
  435.     //  Load the grid with the blank rows to allow data entry
  436.     //
  437.     public void loadEmptyGrid() {
  438.  
  439.         tableContents.currentText = new String[columnCount][50];
  440.         tableContents.cellChanged = null;
  441.         tableContents.rowChanged = null;
  442.         tableContents.columnSelected = null;
  443.         rowKey = new String[50][keyCount];
  444.         tableContents.newTable();
  445.     }
  446.  
  447.     //
  448.     //  Set up the parameters for this grid
  449.     //
  450.     public void setGridSettings() {
  451.  
  452.         tableContents.columnHeader = new String[columnCount];
  453.         tableContents.columnHeaderStyle = new int[columnCount];
  454.         tableContents.columnStyle = new int[columnCount];
  455.         tableContents.columnHeaderColor = new Color[columnCount];
  456.         tableContents.columnColor = new Color[columnCount];
  457.         tableContents.columnBGColor = new Color[columnCount];
  458.         tableContents.columnProtected = new boolean[columnCount];
  459.         tableContents.columnWidth = new int[columnCount];
  460.         tableContents.rightJustify = new boolean[columnCount];
  461.         tableContents.rowHeader = null;
  462.         tableContents.columnHeight = null;
  463.         for (int ix=0; ix<columnCount; ix++) {
  464.             tableContents.columnHeaderStyle[ix] = Font.BOLD;
  465.             tableContents.columnStyle[ix] = Font.PLAIN;
  466.             tableContents.columnHeaderColor[ix] = Color.black;
  467.             tableContents.columnColor[ix] = Color.black;
  468.             tableContents.columnBGColor[ix] = Color.white;
  469.             tableContents.columnStyle[ix] = Font.PLAIN;
  470.         }
  471. >101        tableContents.columnHeader[<ix>] = "<>";
  472. >102        tableContents.columnHeaderStyle[<ix>] = <>;
  473. >103        tableContents.columnStyle[<ix>] = <>;
  474. >104        tableContents.columnHeaderColor[<ix>] = user.u._cvtcolor("<>");
  475. >105        tableContents.columnColor[<ix>] = user.u._cvtcolor("<>");
  476. >106        tableContents.columnBGColor[<ix>] = user.u._cvtcolor("<>");
  477. >107        tableContents.columnProtected[<ix>] = <>;
  478. >108        tableContents.columnWidth[<ix>] = <>;
  479. >109        tableContents.rightJustify[<ix>] = <>;
  480.  
  481.     }
  482.  
  483.     //
  484.     //  The check each rows that has changed and issue an update to the database
  485.     //
  486.     public void checkRows() {
  487.  
  488.         int changedCount = 0;
  489.         int thisCount = 1;
  490.         
  491.         if (!deleteRequested) {
  492.             for (int ix=0; ix<tableContents.rowChanged.length; ix++) {
  493.                 if (tableContents.rowChanged[ix]) {
  494.                     changedCount++;
  495.                 }
  496.             }
  497.             for (int ix=0; ix<tableContents.rowChanged.length; ix++) {
  498.                 if (tableContents.rowChanged[ix]) {
  499.                     if (insertRequested) {
  500.                         user.mainmsg.setStatusMsg("Inserting row " + Integer.toString(thisCount++) + " of " + Integer.toString(changedCount) + "...", 0);
  501.                     } else {
  502.                         user.mainmsg.setStatusMsg("Updating row " + Integer.toString(thisCount++) + " of " + Integer.toString(changedCount) + "...", 0);
  503.                     }
  504.                     saveData(ix);
  505.                     tableContents.rowChanged[ix] = false;
  506.                 }
  507.             }
  508.             if ((insertRequested) && (changedCount > 0)) {
  509.                 loadEmptyGrid();
  510.             }
  511.         } else {
  512.             for (int ix=0; ix<tableContents.rowSelected.length; ix++) {
  513.                 if (tableContents.rowSelected[ix]) {
  514.                     changedCount++;
  515.                 }
  516.             }
  517.             if (changedCount == 0) {
  518.                 user.mainmsg.setStatusMsg("Select the row you wish to remove by clicking on the row number button.", 7);
  519.             } else {
  520.                 for (int ix=0; ix<tableContents.rowSelected.length; ix++) {
  521.                     if (tableContents.rowSelected[ix]) {
  522.                         user.mainmsg.setStatusMsg("Deleting row " + Integer.toString(thisCount++) + " of " + Integer.toString(changedCount) + "...", 0);
  523.                         saveData(ix);
  524.                         tableContents.rowChanged[ix] = false;
  525.                     }
  526.                 }
  527.                 newSearch();
  528.             }
  529.         }
  530.     }
  531.  
  532.     //
  533.     //  Save the selected item
  534.     //
  535.     public boolean saveData(int tableRow) {
  536.  
  537.         int recCount = 0;
  538.         Vector results = new Vector();
  539.         String sep = jaggSQL.getSEP();
  540.         String SQL = "";
  541.  
  542.         if (insertRequested) {
  543. >121            SQL = <INSERT INTO >;
  544.         } else {
  545.             if (deleteRequested) {
  546. >122                SQL = <DELETE FROM >;
  547.             } else {
  548. >123                SQL = <UPDATE >;
  549.             }
  550.         }
  551.  
  552.         recCount = jaggSQL.execSQL(SQL, results);
  553.  
  554.         if (user.DEBUG) System.out.println("saveData CNT: "+Integer.toString(recCount));
  555.  
  556.         if(recCount == -1) {
  557.             System.out.println("saveData SQL: "+SQL);
  558.             user.mainmsg.setStatusMsg("SQL error. Contact the System Administrator.", 10);
  559.             return false;
  560.         }
  561.         if(recCount == 1) {
  562.             if (insertRequested) {
  563.                 user.mainmsg.setStatusMsg("Record successfully added.",3);
  564.             } else 
  565.             if (deleteRequested) {
  566.                 user.mainmsg.setStatusMsg("Record successfully removed.",3);
  567.             } else {
  568.                 user.mainmsg.setStatusMsg("Record successfully updated.",3);
  569.             }
  570.         } else {
  571.             user.mainmsg.setStatusMsg("SQL failed. Contact the System Administrator.", 10);
  572.         }
  573.         deleteRequested = false;
  574.         return true;
  575.  
  576.     }
  577.  
  578.     //
  579.     //  Clear the screen fields for a new option
  580.     //
  581.     public void clearFields() {
  582.  
  583. >037        <username>.setText("");
  584.         loadEmptyGrid();
  585.  
  586.     }
  587.  
  588.     //
  589.     //  Load all of the Screen Choices
  590.     //
  591.     public void loadChoices() {
  592. >043
  593. >044        new JDPLoadChoice(user,jaggSQL,<choicename>,"<choicecolumnname>","<actualcolumnname>","<tablename>","<whereclause>",value<columnname>);
  594.     }
  595.  
  596.     //
  597.     //  Perform component validations
  598.     //
  599.     public boolean checkFields() {
  600.  
  601. >045        if (!user.u.<isnumeric>(<field>,user.mainmsg)) return false;
  602.         return true;
  603.  
  604.     }
  605.  
  606.  
  607. }
  608.